
#include <iostream>


#include "user.pb.h"
#include "mrpcapplication.h" 
#include "mrpcchannel.h"
#include "jsonUtils.h"
#include <netinet/in.h>
static std::string curr_service_name = "UserServiceRpc";

bool callLogin(int formatInt, const std::string& username, const std::string& password){
    std::string curr_method_name = "login";
    bool success;
    std::string message;
    if(formatInt == 0){
        // protobuff
        fixbug::UserServiceRpc_Stub userServiceRpc(new MRpcChanner());
        ::fixbug::LoginRequest request;
        request.set_username(username);
        request.set_password(password);
        ::fixbug::LoginResponse response;

        // 本质上执行的还是channel_->CallMethod
        userServiceRpc.login(nullptr, &request, &response, nullptr);
        success = response.success();
        std::cout << "calllogin response success  : " << response.success() << std::endl;
        std::cout << "calllogin response message  : " << response.message() << std::endl;


    }else{
        // json
        MRpcChanner channel;
        RpcJsonParam param;
        
        param.requestJson = jsonFormatFromKV("username", "zs", "password", "123");
        channel.CallMethodJson(curr_service_name, curr_method_name, param);
        success = param.response.success;
        std::cout << "calllogin response success  : " << (bool)(param.response.success) << std::endl;
        std::cout << "calllogin response message  : " << param.response.message << std::endl;
    }
    
    if(success){
        std::cout << "call login success " << std::endl;
    }else{
        std::cout << "call login faile. message :  " << message << std::endl;
    }
    return success;
}

// void callothermethod
// ...


int main(int argc, char** argv){
    MrpcApplication::init(argc, argv);
    bool result = callLogin(0, "zs", "123");
    // bool result2 = callLogin(1, "zs", "123");
    
}

